﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Reflection;

namespace br.com.SistemaChamados.QueryManager.Utils
{
    public class ReflectionUtils
    {

        public static Object createAnObjectFromType(Type typeClass)
        {
            System.Reflection.Assembly asm = System.Reflection.Assembly.GetAssembly(typeClass);
            Object returnObject = asm.CreateInstance(typeClass.FullName);
            return returnObject;
        }

        public static System.Reflection.PropertyInfo getPropertyByName(Type aType, String aPropertyName)
        {
            PropertyInfo propertyInfo = aType.GetProperty(aPropertyName);
            return propertyInfo;
        }

        public static string[] getPropertyNamesFromObject(Type aType)
        {
            int quantityProperties = aType.GetProperties().Length;
            string[] propertyNames = new string[quantityProperties];
            for (int i = 0; i < quantityProperties; i++)
            {
                propertyNames[i] = aType.GetProperties()[i].Name;
            }
            return propertyNames;
        }

    }
}